<script setup lang="ts">
//瀑布流
import { reactive, watchEffect } from "vue";
import { SingleMeat } from "@/store/interface";
import WaterfallBlock from "@/components/block/waterfall-block.vue";

const props = defineProps<{ data: SingleMeat[] }>();

const state = reactive({
  a: [] as SingleMeat[],
  b: [] as SingleMeat[],
});

// 监听传入值的变化，并重新计算 a 和 b
watchEffect(() => {
  //TODO:这里的逻辑有问题，会导致两列的差距越来越大
  state.a = props.data.filter((_, index) => index % 2 === 0);
  state.b = props.data.filter((_, index) => index % 2 !== 0);
});
</script>
<template>
  <section class="waterfall-wrap">
    <div class="module-title-wrap">
      <h3>更多内容</h3>
      <a href="#" class="link" style="color: rgb(153, 153, 153)">77</a>
    </div>
    <aside class="common-flex-box common-flow-layout goods-scroll">
      <div class="vue-waterfall is-transition">
        <div class="vue-waterfall-column" style="width: 50%">
          <WaterfallBlock :data="item" v-for="item in state.a" :key="item.id" />
        </div>
        <div class="vue-waterfall-column" style="width: 50%">
          <WaterfallBlock :data="item" v-for="item in state.b" :key="item.id" />
        </div>
      </div>
    </aside>
  </section>
</template>
<style scoped lang="less">
.module-title-wrap {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  position: relative;
  padding: 0 1.2rem;
  cursor: pointer;
  height: 1.8rem;
  h3 {
    font-size: 0.8rem;
    font-weight: 700;
    //color: rgba(0, 0, 0, 0.8);
    color: rgb(102, 102, 102);
  }
  .link {
    min-width: 1.1rem;
    height: 1.8rem;
    line-height: 1.8rem;
    z-index: 1;
    right: 1.2rem;
    padding-right: 0.6rem;
    color: rgba(0, 0, 0, 0.4);
    font-weight: 700;
    font-size: 0.7rem;
  }
}
.common-flow-layout {
  width: 100%;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -ms-flex-flow: row wrap;
  flex-flow: row wrap;
  -ms-flex-line-pack: start;
  align-content: flex-start;
  -webkit-box-pack: start;
  -ms-flex-pack: start;
  justify-content: flex-start;
}
.goods-scroll {
  width: calc(100% - 1.2rem);
  margin: 0 auto;
}

.arrow-right-icon:after,
.module-title-wrap .link {
  position: absolute;
  top: 50%;
  -webkit-transform: translateY(-50%);
  transform: translateY(-50%);
}
</style>
